﻿using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using Commands.Scheduling;

namespace Commands.Settings
{
    internal class SettingsHelper
    {
        internal static Settings Settings
        {
            get { return _settings ?? (_settings = _serializer.LoadSettings(SETTINGS_FILE_NAME)); }
        }

        public void Save()
        {
            _serializer.SaveSettings(SETTINGS_FILE_NAME, _settings);
        }

        internal static ISchedule GetSchedule()
        {
            var timeSettings = Settings.TimeSettings;

            return new Schedule(timeSettings);
        }

        private static Settings _settings;

        private static readonly SettingsSerializer<Settings> _serializer = new SettingsSerializer<Settings>(); 

        private const string SETTINGS_FILE_NAME = @"settings.xml";
    }
}
